// 基础设施 / 楼栋管理

import r from '@/utils/request'
import { type ListResponseType, type ResponseType } from '../types'

enum API {
    buildingList = "/building/list", // 楼栋列表
    buildingAdd = "/building/add", // 楼栋添加
    buildingUpdate = "/building/update", // 楼栋修改
    buildingDelete = "/building/delete", // 楼栋删除
    buildingDeleteAll = "/building/deleteAll", // 楼栋批量删除
}

export interface BuildingListResAPI {
    id:           number;
    companyId:    number;
    name:         string;
    addTime:      string;
    addAccountId: number;
    pid:          number;
}

export function getBuildingListAPI():Promise<ListResponseType<BuildingListResAPI>> {
    return r.get(API.buildingList)
}

export interface  buildingAddAndUpdateParams {
    id:   number;
    name: string;
    pid:  number;
}

export interface buildingAddAndUpdateResAPI {
    id:           number;
    companyId:    number;
    name:         string;
    addTime:      string;
    addAccountId: number;
    pid:          number;
}

export function buildingAddAPI(Params:buildingAddAndUpdateParams):Promise<ResponseType<buildingAddAndUpdateResAPI>> {
    return r.post(API.buildingAdd,Params)
}

export function buildingUpdateAPI(Params:buildingAddAndUpdateParams):Promise<ResponseType<buildingAddAndUpdateResAPI>> {
    return r.put(API.buildingUpdate,Params)
}

export function buildingDeleteAPI(id:number):Promise<ResponseType<null>> {
    return r.delete(API.buildingDelete+'/'+id)
}
export function buildingDeleteAllAPI(ids:number[]):Promise<ResponseType<null>> {
    return r.post(API.buildingDeleteAll,ids)
}